package com.zksk.admin.service.member.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksk.admin.domain.market.dto.SaleMemberDto;
import com.zksk.admin.domain.market.vo.SaleMemberRequestVo;
import com.zksk.admin.mapper.member.MemberDao;
import com.zksk.admin.service.member.MarketMemberService;
import com.zksk.common.core.utils.StringUtils;
import com.zksk.mbg.admin.domain.Member;
import com.zksk.mbg.admin.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 营销用户管理 服务实现类
 * </p>
 *
 * @author Zksk Acmen
 * @since 2022-12-15
 */
@Service
public class MarketMemberImpl extends ServiceImpl<MemberMapper, Member> implements MarketMemberService {

    @Autowired
    private MemberDao memberDao;

    /**
     * 分配需要营销得用户列表
     * @param requestVo
     * @return
     */
    @Override
    public IPage<SaleMemberDto> marketingMemberList(SaleMemberRequestVo requestVo) {
        Page<SaleMemberDto> page = memberDao.marketingMemberList(
                new Page<>(requestVo.getPageNum(),requestVo.getPageSize()),
                new QueryWrapper<Member>()
                        .eq(StringUtils.isNotEmpty(requestVo.getMemberId()), "m.member_id", requestVo.getMemberId()) // 企业id
                        .like(StringUtils.isNotEmpty(requestVo.getMemberName()), "m.member_name", requestVo.getMemberName()) // 企业名称
                        .eq(StringUtils.isNotEmpty(requestVo.getMemberLevel()), "m.member_level", requestVo.getMemberLevel()) // 企业等级
                        .eq(StringUtils.isNotEmpty(requestVo.getStationId()), "m.stations_id", requestVo.getStationId()) // 所属平台id
                        .like(StringUtils.isNotEmpty(requestVo.getStationName()), "m.platform_name", requestVo.getStationName()) // 所属平台名称
                        .eq(StringUtils.isNotEmpty(requestVo.getIfSale()), "m.if_sale", requestVo.getIfSale()) // 是否营销
                        .eq(StringUtils.isNotEmpty(requestVo.getChannelId()), "m.channel_id", requestVo.getChannelId())// 所属渠道
                        .like(StringUtils.isNotEmpty(requestVo.getChannelName()), "m.channel_name", requestVo.getChannelName()) // 所属渠道名称
                        .eq(StringUtils.isNotEmpty(requestVo.getSaleUserId()), "m.sale_user", requestVo.getSaleUserId()) // 营销人员
                        .like(StringUtils.isNotEmpty(requestVo.getSaleUserName()), "m.sale_username", requestVo.getSaleUserName())
                        .eq(StringUtils.isNotEmpty(requestVo.getPlanTime()), "m.plan_time", requestVo.getPlanTime())
                        .eq(StringUtils.isNotEmpty(requestVo.getSaleTime()), "sr1.sale_time", requestVo.getSaleTime())

        );
        return page;
    }
}
